<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <script>
        // 递归将数组转成对象
        let originArr = [1, 2, [3, [4, 5], 6], 7, [8], 9];
        function convert(arr) {
            let targeArr = [];
            for (let i = 0; i < arr.length; i++) {
                if (typeof arr[i] == 'object') {
                    targeArr.push({ children: fn(arr[i]) });
                } else {
                    targeArr.push({ value: arr[i] });
                }
            }
            return targeArr;
        }

        function convert2(item) {
            if (typeof item == 'number') {
                return { value: item };
            } else if (Array.isArray(item)) {
                return { children: item.map((_item) => fn2(_item)) };
            }
        }

        console.log(convert([originArr]));
        console.log(convert2(originArr));
    </script>
</body>

</html>